package com.homework;

import java.util.Objects;
import java.util.Scanner;

public class homework4 {
    /*
    分析以下需求，并用代码实现
	1.按照以下描述完成类的定义。
		学生类   属性：
				姓名name
				年龄age
				成绩score
			行为：
			吃饭eat()
			stuty(String content)(content:表示学习的内容)
	2.定义学生工具StudentsTool,有四个方法,描述如下
		public void listStudents(Student[] arr):遍历打印学生信息
		public int getMaxScore(Student[] arr):获取学生成绩的最高分
		public Student getMaxStudent(Student[] arr):获取成绩最高的学员
		public int getAverageScore(Student[] arr):获取学生成绩的平均值
		public int getCount(Student[] arr):获取不及格的学员数量
	3.定义测试类TestStudentTool，在main方法中首先创建长度为5的Student数组并初始化数据,再创建StudentsTool类的对象,并调用以上方法
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Student2[] student2s = new Student2[5];
        for (int i = 0; i < student2s.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个学生的姓名");
            String name = input.next();
            System.out.println("请输入第" + (i + 1) + "个学生的年龄");
            Integer age = input.nextInt();
            System.out.println("请输入第" + (i + 1) + "个学生的成绩");
            Integer score = input.nextInt();
            student2s[i] = new Student2(name,age,score);
        }
        StudentsTool studentsTool = new StudentsTool();
        studentsTool.listStudents(student2s);
        int maxScore = studentsTool.getMaxScore(student2s);
        System.out.println("maxScore = " + maxScore);
        Student2 maxStudent = studentsTool.getMaxStudent(student2s);
        System.out.println("maxStudent = " + maxStudent);
        int averageScore = studentsTool.getAverageScore(student2s);
        System.out.println("averageScore = " + averageScore);
        int count = studentsTool.getCount(student2s);
        System.out.println("count = " + count);
    }
}
class Student2{
    private String name;
    private Integer age;
    private Integer score;
    public void set(){

    }
    public void study(String content){

    }

    public Student2() {
    }

    public Student2(String name, Integer age, Integer score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Integer getScore() {
        return score;
    }

    public void setScore(Integer score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student2{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student2 student2 = (Student2) o;
        return Objects.equals(name, student2.name) && Objects.equals(age, student2.age) && Objects.equals(score, student2.score);
    }

    @Override
    public int hashCode() {
        int result = Objects.hashCode(name);
        result = 31 * result + Objects.hashCode(age);
        result = 31 * result + Objects.hashCode(score);
        return result;
    }
}
class StudentsTool{
    public void listStudents(Student2[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
    public int getMaxScore(Student2[] arr){
        Integer max = arr[0].getScore();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].getScore() > max){
                max = arr[i].getScore();
            }
        }
        return max;
    }
    public Student2 getMaxStudent(Student2[] arr){
        Integer maxScore = getMaxScore(arr);
        int index = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].getScore().equals(maxScore)){
                index = i;
            }
        }
        return arr[index];
    }
    public int getAverageScore(Student2[] arr){
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i].getScore();
        }
        return sum/arr.length;
    }
    public int getCount(Student2[] arr){
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].getScore() < 60){
                count++;
            }
        }
        return count;
    }
}